<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #btn {
            position: absolute;
            left: 10px;
            top: 10px;
        }

        #div {
            width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            left: 50px;
            top: 50px;
        }
    </style>
</head>

<body>
    <button id="btn">回放</button>
    <div id="div">
    </div>
    <script>
        window.onload = function () {
            var oBtn = document.getElementById('btn');
            var oDiv = document.getElementById('div');
            var arr = [];

            oDiv.onmousedown = function (e) {
                var oEvent = e || window.event;

                var divX = oEvent.clientX - oDiv.offsetLeft;
                var divY = oEvent.clientY - oDiv.offsetTop;

                document.onmousemove = function (e) {
                    var oEvent = e || window.event;
                    var l = oEvent.clientX - divX;
                    var t = oEvent.clientY - divY;

                    arr.push({ x: l, y: t });

                    oDiv.style.left = l + 'px';
                    oDiv.style.top = t + 'px';
                };
                document.onmouseup = function () {
                    document.onmousemove = null;
                    document.onmouseup = null;
                };
            };
            oBtn.onclick = function () {
                var timer = setInterval(function () {
                    if (arr.length > 0) {
                        var oData = arr.pop();
                        oDiv.style.left = oData.x + 'px';
                        oDiv.style.top = oData.y + 'px';
                    } else {
                        clearInterval(timer);
                    }
                }, 10);
            };
        };
    </script>
</body>

</html>